home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / Instrumentation SDK / Instrumentation SDK 1.0.5 / Documentation / Sample Code / SampleTrace.c < prev   
Encoding:
C/C++ Source or Header  |  1997-07-08  |  1.4 KB  |  67 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    This code illustrates how to create trace nodes and log trace events to them.
  3.  */
  4.  
  5. #include "Instrumentation.h"
  6.  
  7.  
  8. OSStatus    InitInstrumentation( void);
  9. void        LogTraces( void);
  10.  
  11. InstTraceClassRef        gTraceRef,
  12.                         gTraceWithDataRef;
  13.  
  14. InstDataDescriptorRef    gDataDesc;
  15.  
  16.  
  17. void        main()
  18. {
  19. OSStatus        err;
  20.  
  21.     if ( noErr == ( err = InitInstrumentation()))
  22.         LogTraces();
  23. }
  24.  
  25.  
  26. OSStatus    InitInstrumentation( void)
  27. /* Create and enable our trace instrumentation nodes. */
  28. {
  29. OSStatus        err;
  30.  
  31.     err = InstCreateTraceClass( kInstRootClassRef, "Samples:Trace 1", 'samp', 
  32.                                 kInstEnableClassMask, &gTraceRef);
  33.  
  34.     if ( noErr == err)
  35.         err = InstCreateTraceClass( kInstRootClassRef, "Samples:Trace 2", 'samp', 
  36.                                     kInstEnableClassMask, &gTraceWithDataRef);
  37.  
  38.     if ( noErr == err)
  39.         err = InstCreateDataDescriptor( "%ld", &gDataDesc);
  40.  
  41.     return err;
  42. }
  43.  
  44.  
  45. void        LogTraces( void)
  46. /* Log some traces. */
  47. {
  48. InstEventTag    tag;
  49. UInt32            result;
  50.  
  51.     tag = InstCreateEventTag();        // or any other relatively unique 32-bit value
  52.  
  53.     // log the start time of the routine
  54.     InstLogTraceEvent( gTraceRef, tag, kInstStartEvent);
  55.  
  56.     // do some time-consuming processing here
  57.     // result = foo();
  58.  
  59.     // record the result as a trace
  60.     InstLogTraceEventWithData( gTraceWithDataRef, kInstNoEventTag, kNilOptions, gDataDesc, result);
  61.  
  62.     // log the end time of the routine
  63.     InstLogTraceEvent( gTraceRef, tag, kInstEndEvent);
  64. }
  65.  
  66.  
  67.